package com.cx.core.common.domin;


import com.cx.core.common.constant.ErrorEnum;
import lombok.Getter;
import lombok.Setter;

@Setter
@Getter
public class ApiResult<T> extends BaseEntity{

    private String code;

    private String msg;

    private T data;

    public ApiResult(){}

    public ApiResult(String code, String msg, T data){
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public ApiResult(String code, String msg){
        this.code = code;
        this.msg = msg;
    }

    public ApiResult(ErrorEnum errorEnum){
        this.code = errorEnum.getCode();
        this.msg = errorEnum.getMsg();
    }

    public static ApiResult success(Object data){
        ApiResult apiResult = new ApiResult(ErrorEnum.SUCESS);
        apiResult.setData(data);
        return apiResult;
    }
}
